package com.yxinsur.imc.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxinsur.imc.business.domain.ImcRateFactorValue;
import com.yxinsur.imc.business.enums.IsDeletedEnum;
import com.yxinsur.imc.business.form.RateFactorValueForm;
import com.yxinsur.imc.business.mapper.ImcRateFactorValueMapper;
import com.yxinsur.imc.business.service.IImcRateFactorValueService;
import com.yxinsur.imc.business.vo.RateFactorValueVo;
import com.yxinsur.imc.common.utils.DateUtils;
import com.yxinsur.imc.common.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品费率因子VALUEService业务层处理
 * 
 * @author imc
 * @date 2021-03-30
 */
@Service
public class ImcRateFactorValueServiceImpl extends ServiceImpl<ImcRateFactorValueMapper, ImcRateFactorValue> implements IImcRateFactorValueService
{
    private static final Logger logger = LoggerFactory.getLogger(ImcRateFactorValueServiceImpl.class);

    @Autowired
    private ImcRateFactorValueMapper imcRateFactorValueMapper;

    /**
     * 查询产品费率因子VALUE列表
     * 
     * @param rateFactorValueForm 产品费率因子VALUE
     * @return 产品费率因子VALUE
     */
    @Override
    public List<RateFactorValueVo> selectImcRateFactorValueList(RateFactorValueForm rateFactorValueForm)
    {
        return imcRateFactorValueMapper.selectImcRateFactorValueList(rateFactorValueForm);
    }

    /**
     * 新增产品费率因子VALUE
     * 
     * @param rateFactorValueForm 产品费率因子VALUE
     * @return 结果
     */
    @Override
    public int insertImcRateFactorValue(RateFactorValueForm rateFactorValueForm)
    {
        logger.info("新增产品费率因子VALUE操作：{}",rateFactorValueForm.toString());
        ImcRateFactorValue factorValue = new ImcRateFactorValue();
        BeanUtils.copyProperties(rateFactorValueForm,factorValue);
        factorValue.setCreateTime(DateUtils.getNowDate());
        factorValue.setCreateId(SecurityUtils.getUsername());
        factorValue.setIsDeleted(IsDeletedEnum.N.getCode());
        factorValue.setTenantId(SecurityUtils.getTenantId());
        return this.imcRateFactorValueMapper.insert(factorValue);
    }

    /**
     * 修改产品费率因子VALUE
     * 
     * @param rateFactorValueForm 产品费率因子VALUE
     * @return 结果
     */
    @Override
    public int updateImcRateFactorValue(RateFactorValueForm rateFactorValueForm)
    {
        logger.info("修改产品费率因子KEY操作：{}",rateFactorValueForm.toString());
        ImcRateFactorValue factorValue = this.imcRateFactorValueMapper.selectById(rateFactorValueForm.getId());
        factorValue.setFactorValue(rateFactorValueForm.getFactorValue());
        factorValue.setUpdateTime(DateUtils.getNowDate());
        factorValue.setUpdateId(SecurityUtils.getUsername());
        return this.imcRateFactorValueMapper.updateById(factorValue);
    }

    /**
     * 批量删除产品费率因子VALUE
     * 
     * @param ids 需要删除的产品费率因子VALUEID
     * @return 结果
     */
    @Override
    public int deleteImcRateFactorValueByIds(Long[] ids)
    {
        logger.info("删除产品费率因子VALUE操作：{}",ids);
        int count = 0;
        for(Long id:ids){
            ImcRateFactorValue rateFactorValue = this.imcRateFactorValueMapper.selectById(id);
            rateFactorValue.setIsDeleted(IsDeletedEnum.Y.getCode());
            rateFactorValue.setUpdateId(SecurityUtils.getUsername());
            rateFactorValue.setUpdateTime(DateUtils.getNowDate());
            count += this.imcRateFactorValueMapper.updateById(rateFactorValue);
        }
        return count;
    }
}
